import { Message,MessageBox} from 'element-ui';
import router from './../../router.js'
const city = require('./../../assets/cityData.min.json')
const tipsMsg = (type = 'success', msg = '成功！', time = 1500, close=false) => {
    Message({
      message: msg,
      type: type,
      duration:time,
      customClass:'tipsMsg',
      showClose: close
    });
};
export default {
    tipsMsg,
    gender:function(sex) {
        let info = sex || '';
        if (info == '1') {
            return '女'
        } else if (info == '2') {
            return '男'
        } else if (info == '0'){
            return '保密'
        }
        return "未知"
    },
      // 提醒确认信息
    openTips: function (msg, type = 'warning', btn1 = "确定", btn2 = "取消", showClose = true){
        return new Promise((resolve,reject) => {
            MessageBox({
                title: '提示',
                type: type,
                message: msg,
                confirmButtonText: btn1,
                cancelButtonText: btn2,
                showConfirmButton: true,
                showClose:showClose,
                closeOnClickModal:showClose,
                closeOnPressEscape:showClose
            }).then((e) => {
                console.log(e)
                resolve(e);
            }).catch((e) => {
                console.log(e)
                reject(e);
            });
        })
    },
    loginOutPage:() => {
        // 清空本地的登录信息
        sessionStorage.removeItem('userInfo');
        router.push({path:'login'});
    },
    // 获取登陆的用户信息
    getUserInfo : () => {
        const location = sessionStorage.getItem('userInfo');
        let info = location ? JSON.parse(location) : {};
        return info
    },
    city_lop (arr) {
        let cityArray = city;
        const lop = (cityArray, arr) => {
          for (let i = 0; i < cityArray.length; i++) {
            const prov = cityArray[i];
            let obj = { value: prov.label, label: prov.label ,id:i};
            if (prov.children) {
              obj.children = [];
              lop(prov.children, obj.children);
            }
            arr.push(obj);
          }
        }
        lop(cityArray, arr);
      },
}